package org.sjlt.marc.workers;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.sjlt.marc.common.BigHelpDBConnection;
import org.sjlt.marc.common.Queries;

public class CreateUser implements Runnable, Serializable 
{
	private static final long serialVersionUID = 838161834988951194L;
	
	String UserId;
	String FName;
	String MInitial; 
	String LName; 
	String Pref_Name; 
	Date DOB; 
	String Gender; 
	String Address; 
	String City; 
	String Zip; 
	String Phone; 
	String Email; 
	String Shirt; 
	String School; 
	Integer Grade;
	String Highest_Sacrament; 
	Integer Confirmation; 
	String Access_Level; 
	String InsuranceCo; 
	String InsuranceNum; 
	String Medications; 
	String Allergies; 
	String MedicalIssues; 
	Integer PermissionToTreat;
	String EmgContact; 
	String EmgRelation; 
	String EmgNumber; 
	String ReportsTo; 
	String Picture;

	public CreateUser(String UserId, String FName, String MInitial, String LName, String Pref_Name, Date DOB, String Gender, String Address, String City, String Zip, String Phone, String Email, String Shirt, String School, Integer Grade,
			String Highest_Sacrament, Integer Confirmation, String Access_Level, String InsuranceCo, String InsuranceNum, String Medications, String Allergies, String MedicalIssues, Integer PermissionToTreat,
			String EmgContact, String EmgRelation, String EmgNumber, String ReportsTo, String Picture)
	{
		this.UserId = UserId;
		this.FName = FName;
		this.MInitial = MInitial;
		this.LName = LName;
		this.Pref_Name = Pref_Name;
		this.DOB = DOB;
		this.Gender = Gender;
		this.Address = Address;
		this.City = City;
		this.Zip = Zip;
		this.Phone = Phone;
		this.Email = Email;
		this.Shirt = Shirt;
		this.School = School;
		this.Grade = Grade;
		this.Highest_Sacrament = Highest_Sacrament;
		this.Confirmation = Confirmation;
		this.Access_Level = Access_Level;
		this.InsuranceCo = InsuranceCo;
		this.InsuranceNum = InsuranceNum;
		this.Medications = Medications;
		this.Allergies = Allergies;
		this.MedicalIssues = MedicalIssues;
		this.PermissionToTreat = PermissionToTreat;
		this.EmgContact = EmgContact;
		this.EmgRelation = EmgRelation;
		this.EmgNumber = EmgNumber;
		this.ReportsTo = ReportsTo;
		this.Picture = Picture;
	}

	public void run()
	{
		BigHelpDBConnection bhdb = new BigHelpDBConnection("sjlt_marc");
		try
		{
			Connection conn = bhdb.getConnection();
			try
			{
				PreparedStatement ps = conn.prepareStatement(Queries.SQL_NEW_USER);
				try
				{
						ps.setString(1, this.UserId);
						ps.setString(2, this.FName);
						ps.setString(3, this.MInitial);
						ps.setString(4, this.LName);
						ps.setString(5, this.Pref_Name);
						ps.setDate(6, this.DOB);
						ps.setString(7, this.Gender);
						ps.setString(8, this.Address);
						ps.setString(9, this.City);
						ps.setString(10, this.Zip);
						ps.setString(11, this.Phone);
						ps.setString(12, this.Email);
						ps.setString(13, this.Shirt);
						ps.setString(14, this.School);
						ps.setInt(15, this.Grade);
						ps.setString(16, this.Highest_Sacrament);
						ps.setInt(17, this.Confirmation);
						ps.setString(18, this.Access_Level);
						ps.setString(19, this.InsuranceCo);
						ps.setString(20, this.InsuranceNum);
						ps.setString(21, this.Medications);
						ps.setString(22, this.Allergies);
						ps.setString(23, this.MedicalIssues);
						ps.setInt(24, this.PermissionToTreat);
						ps.setString(25, this.EmgContact);
						ps.setString(26, this.EmgRelation);
						ps.setString(27, this.EmgNumber);
						ps.setString(28, this.ReportsTo);
						ps.setString(29, this.Picture);
						
						ps.executeUpdate();
				}
				catch(SQLException se)
				{
						se.printStackTrace();
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
				finally
				{
					ps.close();
				}
			}
			finally
			{
				bhdb.closeConnection();
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			bhdb.closeConnection();
		}
	}
}
